Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

251
Views
Rails - ActionCable: "action_cable.url" for Kubernetes/Minikube

What config.action_cable.url should be configured for websockets / Rails / Kubernetes /Minukube with Nginx?

When running "docker-compose" locally an Nginx processes in front of a Rails process (not API only, but with SSR) and a standalone Cable process (cf the guides), the websockets work fine by passing the following server-side (in say "/config/application.rb", with action_cable_meta_tag set in the layouts):

config.action_cable.url = 'ws://localhost:28080'

I am targetting Kubernetes with Minikube locally: I deployed Nginx in front of a Rails deployment (RAILS_ENV=production) along with a Cable deployment but I can't make it work. The Cable service is internal of type "ClusterIP", with "port" and "targetPort". I tried several variations.

Any advice?

Note that I use Nginx -> Rails + Cable on Minikube, and the entry-point is the Nginx service, external of kind LoadBalancer where I used:

upstream rails {
  server rails-svc:3000;
}
server {
  listen 9000 default_server;
  root /usr/share/nginx/html;
  try_files  $uri @rails;
  add_header  Cache-Control public;
  add_header  Last-Modified "";
  add_header  Etag "";
      

  location @rails {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header Host $http_host;
    proxy_pass_header   Set-Cookie;
    proxy_redirect off;
    proxy_pass http://rails;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}

To allow any origin, I also set:

config.action_cable.disable_request_forgery_protection = true
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I have an answer: in a Minikube cluster, don't put anything and disable forgery protection, Rails will default the correct value. When Nginx is front of a Rails pod and a standalone ActionCable/websocket pod (the Rails image is launched with bundle exec puma -p 28080 cable/config.ru), if I name "cable-svc" the service that exposes the ActionCable container, and "rails-svc" the one for the Rails container, you need to:

  • in K8, don't set the config for CABLE_URI
  • in the Rails backend, you don't have the URL (unknown 127.0.0.1:some_port), do:
# config.action_cable.url <-- comment this
config.action_cable.disable_request_forgery_protection=true
  • in the Nginx config, add a specific location for the "/cable" path:
upstream rails {
  server rails-svc:3000;
}
server {
  [...root, location @rails {...}]
  location /cable {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_pass "http://cable-svc:28080";
  }
}

Check the logs, no more WebSockets in Rails, and Cable responds.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!